<template>
	<view class="pd mt70">
		<view class="formrow ">
			<view class="z9 fz28">
				当前账号密码
			</view>
			<view class="mt20 pr  ">
				<input type="text" password="" value="" class="jhhgerttyt" placeholder="请输入密码" v-model="pwd.current"/>
			</view>
		</view>
	<view class="formrow mt70">
		<view class="z9 fz28">
			新密码
		</view>
		<view class="mt20 pr  ">
			<input type="text" password="" value="" class="jhhgerttyt" placeholder="不少于6位数，字母+数字+下划线组合" v-model="pwd.new" @input="checkself"/>
		</view>
	</view>
		<view class="mt100 gedrert">
			<view :class="checklevel>0?'iss':''">
				
			</view>
			<view :class="checklevel>1?'iss':''">
				
			</view>
			<view :class="checklevel>2?'iss':''">
				
			</view>
		</view>
		<view class="fz26 cf cen  mt20">
			安全
		</view>
		<view class="formrow mt70">
			<view class="z9 fz28">
				确认密码
			</view>
			<view class="mt20 pr  ">
				<input type="text" password="" value="" class="jhhgerttyt" placeholder="再次确认密码" v-model="pwd.confirm"/>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tel: '',
				pwd:{
					current:"",
					new:"",
					confirm:""
				},
				checklevel:0
			}
		},
		components: {},
		methods: {
			// 判断密码安全等级
			checkself(){
				console.log(this.pwd.new);
				this.checklevel = this.AnalyzePasswordSecurityLevel(this.pwd.new)
				console.log(this.checklevel)
			},
			AnalyzePasswordSecurityLevel(password) {
			    var securityLevelFlag = 0;
			    if (password.length < 6) {
			        return 0;
			    }
			    else {
			        if (/[a-z]/.test(password)){
			            securityLevelFlag++;    //lowercase
			        }
			        if (/[A-Z]/.test(password)){
			            securityLevelFlag++;    //uppercase
			        } 
			        if(/[0-9]/.test(password)){
			            securityLevelFlag++;    //digital
			        }
			        if(this.containSpecialChar(password)){
						uni.showToast({
							title:'密码不能包含特殊字符',
							icon:'none'
						})
						this.pwd.new = ''
						return false
			            // securityLevelFlag++;    //specialcase
			        }
			        return securityLevelFlag;
			    }
			},
			 containSpecialChar(str)   
			{   
			    var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
			    return (containSpecial.test(str));   
			},
			qyuehhsd(){
				uni.navigateTo({
					url:"LoginAndRegistration"
				})
			},
			async accomplish(){
				if(!this.pwd.current){
					uni.showToast({
						icon: "none",
						title: '请输入当前账号'
					})
					return
				}
				if(!this.pwd.new){
					uni.showToast({
						icon: "none",
						title: '请输入新密码'
					})
					return
				}
				if(this.pwd.new.length<6){
					uni.showToast({
						icon: "none",
						title: '密码长度须大于六位'
					})
					return
				}
				if(!this.pwd.confirm){
					uni.showToast({
						icon: "none",
						title: '请输入确认密码'
					})
					return
				}
				if(this.pwd.confirm !=this.pwd.new){
					uni.showToast({
						icon: "none",
						title: '两次输入密码不一致'
					})
					return
				}
				let val={}
				val.old_password=this.pwd.current
				val.password=this.pwd.new
				val.password_confirmation=this.pwd.confirm
				let fetch= await this.get('/api/password',val,"PUT")
				console.log("mima",fetch)
				if(fetch.code==0){
					uni.navigateTo({
						url:"/pages/user/LoginAndRegistration"
					})
				}
			}
		},
		onNavigationBarButtonTap(e) {
			// uni.redirectTo({
			// 	url:'ReplaceSuccess'
			// })
			this.accomplish()
		},
		mounted() {}
	}
</script>
<style scoped>
	.gedrert {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		grid-column-gap: 20upx;
	}
	.gedrert view{
		background-color: #aaaaaa;
		height: 6upx;
	}
	.gedrert .iss{
		background-color: #1689D5;
	}
	.mt180{
		margin-top: 180upx !important;
	}
</style>
